<template>
<div>
    <div>
    <el-card class="box-card" style="margin-left: auto; margin-right: auto;">
        <div slot="header" class="clearfix">
            <span>报修管理</span>
        </div>
        <div>
          <span style=" float: left; margin-top: 10px;">报修人</span>
          <el-input style="float: left; width: 20%; margin-bottom: 20px;  margin-left: 20px;" v-model="owner"></el-input>
          <el-button type="primary" icon="el-icon-circle-plus" style="float: right; " @click="repairSelect(owner)">查询</el-button>
        </div>
    </el-card>
    <el-card class="box-card" style="margin-left: auto; margin-right: auto;">
        <div slot="header" class="clearfix">
            <span>报修列表</span>
            <el-button type="primary" icon="el-icon-circle-plus" style="float: right; " @click="Add(),dialogFormVisible1 = true">新建</el-button>
        </div>
        <div>
            <el-table
            :data="InfoList"
            style="width: 100%">
            <el-table-column
                prop="communityName"
                label="报修房屋"
                width="200">
            </el-table-column>
            <el-table-column
                prop="theProjectName"
                label="维修项目"
                width="100">
            </el-table-column>
            <el-table-column
                prop="theTitle"
                label="标题"
                width="100">
            </el-table-column>
            <el-table-column
                prop="owner"
                label="报修人"
                width="100">
            </el-table-column>
            <el-table-column
                prop="appointmentTime"
                label="预约日期"
                width="180">
            </el-table-column>
            <el-table-column
                prop="maintenanceProcess"
                label="状态"
                width="180">
            </el-table-column>
            <el-table-column
                fixed="right"
                label="操作"
                width="200">
                <template slot-scope="scope">
                    <!-- <el-button  type="text" size="small">审核</el-button> -->
                    <el-button  type="text" size="small" @click="Update(scope.row),dialogFormVisible= true">编辑</el-button>
                    <el-button type="text" size="small" @click="repairDelect(scope.row.maintenanceId)">删除</el-button>
                </template>
            </el-table-column>
            </el-table>
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[2, 4, 6, 8]"
              :page-size="2"
              layout="total, sizes, prev, pager, next, jumper"
              :total="pageTotal">
            </el-pagination>
        </div>
    </el-card>
  </div>
  <div>
        <el-dialog title="新增" :visible.sync="dialogFormVisible1">
            <el-form :model="ruleForm" status-icon  ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="报修房屋" >
                <el-input v-model="ruleForm.communityName"></el-input>
                </el-form-item>
                <el-form-item label="维修项目" >
                  <el-select v-model="ruleForm.projectTypeId" placeholder="请选择">
                    <el-option
                      v-for="item in options1"
                      :key="item.projectTypeId"
                      :label="item.theProjectName"
                      :value="item.projectTypeId">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="标题" >
                <el-input v-model="ruleForm.theTitle"></el-input>
                </el-form-item>
                <el-form-item label="详细内容" >
                <el-input v-model="ruleForm.problemDescription"></el-input>
                </el-form-item>
                <el-form-item label="报修人" >
                <el-input v-model="ruleForm.owner"></el-input>
                </el-form-item>
                <el-form-item label="手机号" >
                <el-input v-model="ruleForm.phone"></el-input>
                </el-form-item>
                <el-form-item label="预约日期" >
                <div class="block">
                  <el-date-picker
                    v-model="ruleForm.appointmentTime"
                    type="datetime"
                    placeholder="选择日期时间"
                    value-format="yyyy-MM-dd HH:mm:ss"
                   >
                  </el-date-picker>
                </div>
                </el-form-item>
                <el-form-item >
                <el-button type="primary" @click="repairAdd('ruleForm')">提交</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <el-dialog title="编辑" :visible.sync="dialogFormVisible">
            <el-form :model="ruleForm" status-icon  ref="ruleForm" label-width="100px" class="demo-ruleForm">
                <el-form-item label="报修房屋" >
                <el-input v-model="ruleForm.communityName"></el-input>
                </el-form-item>
                <el-form-item label="维修项目" >
                  <el-select v-model="ruleForm.projectTypeId" placeholder="请选择">
                    <el-option
                      v-for="item in options1"
                      :key="item.projectTypeId"
                      :label="item.theProjectName"
                      :value="item.projectTypeId">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="标题" >
                <el-input v-model="ruleForm.theTitle"></el-input>
                </el-form-item>
                <el-form-item label="详细内容" >
                <el-input v-model="ruleForm.problemDescription"></el-input>
                </el-form-item>
                <el-form-item label="报修人" >
                <el-input v-model="ruleForm.owner"></el-input>
                </el-form-item>
                <el-form-item label="手机号" >
                <el-input v-model="ruleForm.phone"></el-input>
                </el-form-item>
                <el-form-item label="预约日期" >
                <div class="block">
                  <el-date-picker
                    v-model="ruleForm.appointmentTime"
                    type="datetime"
                    placeholder="选择日期时间"
                    value-format="yyyy-MM-dd HH:mm:ss"
                   >
                  </el-date-picker>
                </div>
                </el-form-item>
                <el-form-item >
                <el-button type="primary" @click="repairUpdate('ruleForm')">提交</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
  </div>
</div>
</template>

<script>
export default {
  data() {
        return {
          tableData: [],
          InfoList:[],
          input: '',
          dialogFormVisible: false,
          dialogFormVisible1: false,
          ruleForm:{
            maintenanceId:'',
            communityName:'',
            projectTypeId:'',
            theTitle:'',
            problemDescription:'',
            owner:'',
            phone:'',
            appointmentTime:''
          },
          owner:'',
          pageTotal: 0, // 总数
          pageNum: 1, // 页数
          pageSize: 2, // 条数
          currentPage: 1, // 分页中当前页变量
          options1:[{
            projectTypeId:'1',
            theProjectName:'冰箱'
          },{
            projectTypeId:'2',
            theProjectName:'水暖'
          },{
            projectTypeId:'3',
            theProjectName:'电源开关'
          },{
            projectTypeId:'4',
            theProjectName:'沙发'
          },{
            projectTypeId:'5',
            theProjectName:'地板'
          },{
            projectTypeId:'6',
            theProjectName:'桌子'
          },],
        }

    },
    methods: {
          findAll(){
              this.$axios.get("http://localhost:9000/serverchy/Repair/selectAll").then(response=>{
                  this.InfoList=response.data.data.list
              }
              ).catch(e=>{
              })
          },
          repairDelect(maintenanceId){
              this.$confirm('此操作将永久删除用户信息, 是否继续?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
              }).then(() => {
              this.$axios.get("http://localhost:9000/serverchy/Repair/repairDelect",{
                  params: {
                  maintenanceId: maintenanceId
                  }
              }).then(response=>{
                  this.findAll();
                  this.$message({
                  message: '删除成功',
                  type: 'success'
                  })
              }).catch(e=>{  
              })
              }).catch(e=>{   
              })
          },
          Update(data){
                this.ruleForm.maintenanceId=data.maintenanceId
                this.ruleForm.communityName= data.communityName
                this.ruleForm.projectTypeId= data.projectTypeId
                this.ruleForm.theTitle=data.theTitle
                this.ruleForm.problemDescription=data.problemDescription
                this.ruleForm.owner=data.owner
                this.ruleForm.phone=data.phone
                this.ruleForm.appointmentTime=data.appointmentTime
            },
          Add(){
              this.ruleForm.communityName= ''
              this.ruleForm.projectTypeId= ''
              this.ruleForm.theTitle=''
              this.ruleForm.problemDescription=''
              this.ruleForm.owner=''
              this.ruleForm.phone=''
              this.ruleForm.appointmentTime=''
          },
          repairAdd(){
                this.$axios.post("http://localhost:9000/serverchy/Repair/repairAdd",{
                communityName: this.ruleForm.communityName,
                projectTypeId: this.ruleForm.projectTypeId,
                theTitle: this.ruleForm.theTitle,
                problemDescription:this.ruleForm.problemDescription,
                owner:this.ruleForm.owner,
                phone:this.ruleForm.phone,
                appointmentTime:this.ruleForm.appointmentTime
              }).then(response=>{
                  this.repairSelect();
                  this.dialogFormVisible1=false
                  this.$message({
                    message: '添加成功',
                    type: 'success'
                  })
              }).catch(e=>{
                  this.$message.error('添加失败')
              })
          },
          repairUpdate(){
                this.$axios.post("http://localhost:9000/serverchy/Repair/repairUpdate",{
                maintenanceId: this.ruleForm.maintenanceId,
                projectTypeId: this.ruleForm.projectTypeId,
                theTitle: this.ruleForm.theTitle,
                problemDescription:this.ruleForm.problemDescription,
                owner:this.ruleForm.owner,
                phone:this.ruleForm.phone,
                appointmentTime:this.ruleForm.appointmentTime
              }).then(response=>{
                  this.repairSelect();
                  this.dialogFormVisible=false
                  this.$message({
                    message: '修改成功',
                    type: 'success'
                  })
              }).catch(e=>{
                  this.$message.error('修改失败')
              })
          },
          handleSizeChange(val) {
            this.pageSize = val
            this.repairSelect()
          },
          handleCurrentChange(val) {
            this.pageNum =val
            this.repairSelect()
          },
          repairSelect() {
              // 获取所有用户信息
              this.$axios.get("http://localhost:9000/serverchy/Repair/repairSelect",{
                params:{
                  pageNum: this.pageNum,
                  pageSize: this.pageSize,
                  owner:this.owner
                }
            }).then((res) => {
                this.InfoList = res.data.list
                this.pageTotal = res.data.total
              });
          },
    },
    mounted() {
      this.repairSelect()
    }
}
</script>

<style>
    .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 1136px;
  }
</style>